package com.demo.redis.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * 描述：
 * 作者 张超
 * 时间 2018/6/1
 * 项目 springboot-demo v2.0
 * 版本 v1.0
 */
@Configuration
public class ConfigRedis {
    @Bean
    public RedisTemplate<Object, Object> getRedisTemplate( RedisConnectionFactory redisConnectionFactory) {
        System.err.println("1111111111111111111111111;l111111");
        RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
        redisTemplate.setKeySerializer(stringRedisSerializer);
        redisTemplate.setHashKeySerializer(stringRedisSerializer);
        redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
        redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);

        redisTemplate.setEnableTransactionSupport(true);
        return redisTemplate;
    }
//    @Bean
//    public JedisConnectionFactory getJedisConnectionFactory(){
//        JedisConnectionFactory factory = new JedisConnectionFactory();
//        factory.set
//        return factory;
//
//    }

//    @Bean
//    public JedisPoolConfig getJedisPoolConfig(){
//        JedisPoolConfig poolConfig = new JedisPoolConfig();
//
//        poolConfig.setTestOnBorrow(true);
//        return poolConfig;
//    }
}
